package com.pxst.agent.controller;

import com.pxst.agent.entity.SysRebateScheme;
import com.pxst.agent.req.RebateCreateReq;
import com.pxst.agent.req.RebateReq;
import com.pxst.agent.resp.RebateCreateResp;
import com.pxst.agent.resp.RebateInfo;
import com.pxst.agent.resp.RebateListResp;
import com.pxst.agent.service.SysRebateSchemeService;
import com.pxst.annotations.LogOperate;
import com.pxst.resp.ApiResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;


/**
* @author zarke
* @since 2023-09-12 15:20:01
*/
@RestController
@RequestMapping("/api/rebate")
@Api(tags = "返点设置相关接口")
public class SysRebateSchemeController {

    @Autowired
    private SysRebateSchemeService sysRebateSchemeService;

    @GetMapping("/simple")
    @ApiOperation(value = "回扣方案下拉框信息")
    public ApiResp<?> getRebateInfo(@RequestParam("with") String with ,
                                     @RequestParam(value = "details",required = false) Integer details ) {
        if (details == null && "type".equals(with)){
            return sysRebateSchemeService.getRebateInfo();
        }else if (details != null && details == 1 && "type".equals(with)) {
            return sysRebateSchemeService.getRebateByDetails();
        }else{
            return ApiResp.bussError("参数错误。");
        }
    }

    @GetMapping
    @ApiOperation(value = "搜索")
    public ApiResp<RebateListResp> getRebateList(RebateReq rebateReq) {
        return sysRebateSchemeService.getRebateList(rebateReq);
    }

    @PostMapping
    @ApiOperation(value = "新增")
    @LogOperate(operate = "新增", service = SysRebateSchemeService.class, type = "add")
    @PreAuthorize("@ss.hasAnyPermissions('agent:rebate:create')")
    public ApiResp<RebateCreateResp> createRebate(@RequestBody RebateCreateReq rebateReq) {
        return sysRebateSchemeService.createRebate(rebateReq);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "方案详情")
    public ApiResp<RebateCreateResp> getRebateById(@PathVariable Long id) {
        return sysRebateSchemeService.getRebateById(id);
    }
}
